{extend name='common/content' /}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    {if auth("$classuri/statusAll")}
    <button type="button" class="layui-btn" id="statusAll">批量审核</button>
    {/if}
    {if auth("$classuri/statusCancelAll")}
    <button type="button" class="layui-btn layui-btn-normal" id="statusCancelAll">取消审核</button>
    {/if}
    {if auth("$classuri/add")}
    <button data-open='{:url("$classuri/add")}' data-title="添加" class='layui-btn layui-btn-small'><i
            class='fa fa-plus'></i> 添加
    </button>
    {/if}
    {if auth("$classuri/del")}
    <button data-update data-field='delete' data-action='{:url("$classuri/del")}'
            class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除
    </button>
    {/if}
</div>
{/block}

{block name="content"}

<script type="text/javascript" src="__STATIC__/admin/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/ueditor/ueditor.all.min.js"></script>

<!-- 表单搜索 开始 -->
<form class="layui-form layui-form-pane form-search" action="__SELF__" onsubmit="return false" method="get">

    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">名称</label>
        <div class="layui-input-inline">
            <input name="title" value="{$Think.get.title|default=''}" placeholder="请输入名称" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">分类</label>
        <div class="layui-input-inline">
            <select name='cid' class='layui-select'>
                <option value="">请选择分类</option>
                {foreach $drugCateList as $val}
                {eq name='val.id' value='$Think.get.cid|default=0'}
                <option selected  value='{$val.id}'>{$val.title}</option>
                {else/}
                <option  value='{$val.id}'>{$val.title}</option>
                {/eq}
                {/foreach}
            </select>
        </div>
    </div>
    
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label" style="width:auto">民族</label>
        <div class="layui-input-inline">
            <select name='nid' class='layui-select'>
                <option value="">请选择民族</option>
                {foreach $nationList as $val}
                {eq name='val.id' value='$Think.get.nid|default=0'}
                <option selected  value='{$val.id}'>{$val.title}</option>
                {else/}
                <option  value='{$val.id}'>{$val.title}</option>
                {/eq}
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
    </div>
</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="" method="POST">
    <input type="hidden" value="resort" name="action"/>
    <div class="layui-form">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>
                    <input data-none-auto="" data-check-target='.list-check-box' lay-skin="primary" lay-filter="allChoose" type="checkbox">
                </th>
                <th class='text-center'>名称</th>
                <th class='text-center'>别名</th>
                <th class='text-center'>缩略图</th>
                <th class='text-center'>分类</th>
                <th class='text-center'>民族</th>
                <!-- <th class='text-center'>疾病</th> -->
                <!-- <th class='text-center'>整理者</th> -->
                <th class='text-center'>时间</th>
                <th class='text-center'>状态</th>
                <th class='text-center'>操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $key=>$vo}
            <tr>
                <td>
                    <input class="list-check-box" value='{$vo.id}' lay-skin="primary" type="checkbox">
                </td>
                <td class='text-center'>{$vo.title}</td>
                <td class='text-center'>{$vo.alias}</td>
                <td class='text-center'>
                    <img data-tips-image="" src="{$vo.thumb}" height="30" >
                </td>
                <td class='text-center'>{$vo.cid|get_model_value='Drugcate', 'title'}</td>
                <td class='text-center'>{$vo.nid|get_ext_title='Nation', 'title'}</td>
                <!-- <td class='text-center'>{$vo.did|get_model_value='Disease', 'title'}</td> -->
                <!-- <td class='text-center'>{$vo.userid|get_model_value='Client', 'username'|default="<span style='color:#ccc'>未设置</span>"}</td> -->
                <td class='text-center'>{$vo.createtime|date='Y-m-d', ###}</td>
                <td class='text-center'>
                    {if $vo.status eq 1}
                    <span style="color:#090">已审核</span>
                    {else/}
                    <span>未审核</span>
                    {/if}
                </td>
                <td class='text-center nowrap'>
                    <div class="layui-btn-group">
                        {if $vo.status eq 1 and auth("$classuri/forbid")}
                        <button type="button" data-update="{$vo.id}" data-field='status' data-value='0' data-action='{:url("$classuri/forbid")}' class="layui-btn layui-btn-primary layui-btn-small">取消审核</button>
                        {elseif auth("$classuri/resume")}
                        <button type="button" data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/resume")}' class="layui-btn layui-btn-primary layui-btn-small">通过审核</button>
                        {/if}

                        {if auth("$classuri/edit")}
                        <button type="button" data-open='{:url("$classuri/edit")}?id={$vo.id}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                        {/if}

                        {if auth("$classuri/del")}
                        <button type="button" data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del")}' class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon"></i></button>
                        {/if}
                    </div>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    {if isset($page)}<p>{$page}</p>{/if}
</form>

<script>window.form.render();</script>

<script>
    layui.use('table', function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;

        //全选
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });

        $('#statusAll').click(function(){
            layer.confirm('确认要审核选中的数据吗？', {icon: 3}, function(index) {
                layer.close(index);
                // var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                // console.log($('.layui-form-checked'));return false;
                var ids = [];
                $($('.layui-form-checked')).each(function (i, o) {
                    // console.log($(o).prev().attr('value'));return false;
                    ids.push($(o).prev().attr('value'));
                });
                if(ids==''){
                    layer.msg('请选择要审核的数据！', {time: 1000, icon: 2});
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('statusAll')}", {ids: ids,catid:'{:input("catid")}'}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        window.location.reload();
                        tableIn.reload({where:{catid:'{:input("catid")}'}});
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

        $('#statusCancelAll').click(function(){
            layer.confirm('确认要取消审核选中的数据吗？', {icon: 3}, function(index) {
                layer.close(index);
                // var checkStatus = table.checkStatus('content'); //content即为参数id设定的值
                var ids = [];
                $($('.layui-form-checked')).each(function (i, o) {
                    // console.log($(o).prev().attr('value'));return false;
                    ids.push($(o).prev().attr('value'));
                });
                if(ids==''){
                    layer.msg('请选择要取消审核的数据！', {time: 1000, icon: 2});
                    return false;
                }
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('statusCancelAll')}", {ids: ids,catid:'{:input("catid")}'}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        window.location.reload();
                        tableIn.reload({where:{catid:'{:input("catid")}'}});
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })

    });
</script>

{/block}